/*
 * @lc app=leetcode.cn id=1154 lang=javascript
 *
 * [1154] 一年中的第几天
 */

// @lc code=start
/**
 * @param {string} date
 * @return {number}
 */
var dayOfYear = function (date) {
  const months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  const [year, month, day] = date.split('-');
  if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
    months[2] = 29;
  }
  let sum = 0;
  for (let i = 1; i < month; i++) {
    sum += months[i];
  }
  sum += +day;
  return sum;
};
// @lc code=end
